package com.example.jrfwcwgl.service.impl;

import com.example.jrfwcwgl.entity.TCwReceiptPlan;
import com.example.jrfwcwgl.mapper.TCwReceiptPlanMapper;
import com.example.jrfwcwgl.service.ITCwReceiptPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.org.dto.TCwReceiptPlanDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 收款计划表 服务实现类
 * </p>
 *
 * @author 龚梦
 * @since 2021-04-08
 */
@Service
@Slf4j
public class TCwReceiptPlanServiceImpl extends ServiceImpl<TCwReceiptPlanMapper, TCwReceiptPlan> implements ITCwReceiptPlanService {


    @Autowired
    private TCwReceiptPlanMapper tCwReceiptPlanMapper;

    @Override
    public PageInfo<TCwReceiptPlan> sellist(TCwReceiptPlanDto tCwReceiptPlanDto) {


        PageHelper.startPage(tCwReceiptPlanDto.getPageNum(), tCwReceiptPlanDto.getPageSize());
        String[] ysrq = tCwReceiptPlanDto.getYsrq();
        if (ysrq != null) {
            for (int i = 0; i < ysrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setYsstart(ysrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setYsend(ysrq[i]);
                }
            }
        }
        String[] ssrq = tCwReceiptPlanDto.getSsrq();
        if (ssrq != null) {
            for (int i = 0; i < ssrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setSsstart(ssrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setSsend(ssrq[i]);
                }
            }
        }
        List<TCwReceiptPlan> list = tCwReceiptPlanMapper.list(tCwReceiptPlanDto);
        PageInfo<TCwReceiptPlan> info = new PageInfo<>(list);
        log.info(tCwReceiptPlanDto.toString() + "===");
        return info;
    }

    @Override
    public TCwReceiptPlan getyingshou(TCwReceiptPlanDto tCwReceiptPlanDto) {
        String[] ysrq = tCwReceiptPlanDto.getYsrq();
        if (ysrq != null) {
            for (int i = 0; i < ysrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setYsstart(ysrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setYsend(ysrq[i]);
                }
            }
        }
        String[] ssrq = tCwReceiptPlanDto.getSsrq();
        if (ssrq != null) {
            for (int i = 0; i < ssrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setSsstart(ssrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setSsend(ssrq[i]);
                }
            }
        }
        TCwReceiptPlan tCwReceiptPlan = tCwReceiptPlanMapper.getyingshou(tCwReceiptPlanDto);
        return tCwReceiptPlan;
    }

    @Override
    public TCwReceiptPlan getshishou(TCwReceiptPlanDto tCwReceiptPlanDto) {
        String[] ysrq = tCwReceiptPlanDto.getYsrq();
        if (ysrq != null) {
            for (int i = 0; i < ysrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setYsstart(ysrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setYsend(ysrq[i]);
                }
            }
        }
        String[] ssrq = tCwReceiptPlanDto.getSsrq();
        if (ssrq != null) {
            for (int i = 0; i < ssrq.length; i++) {
                if (i == 0) {
                    tCwReceiptPlanDto.setSsstart(ssrq[i]);
                }
                if (i == 1) {
                    tCwReceiptPlanDto.setSsend(ssrq[i]);
                }
            }
        }
        TCwReceiptPlan tCwReceiptPlan = tCwReceiptPlanMapper.getshishou(tCwReceiptPlanDto);
        return tCwReceiptPlan;
    }


}
